import { createRouter, createWebHistory } from 'vue-router'

const Layout = () => import('@/views/Layout/Layout')
const Home = () => import('@/views/Home')
const TopCategory = () => import('@/views/Category/index.vue')
const SubCategory = () => import('@/views/Category/sub.vue')
const Goods = () => import('@/views/Goods/index')
const Login = () => import('@/views/Login/index.vue')
const LoginCallback = () => import('@/views/Login/callback.vue')
const Cart = () => import('@/views/Cart/index.vue')

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      { path: '/', component: Home },
      { path: 'category/:id', component: TopCategory },
      { path: 'category/sub/:id', component: SubCategory },
      { path: 'product/:id', component: Goods },
      { path: 'cart', component: Cart }
    ]
  },
  { path: '/login', component: Login },
  { path: '/login/callback', component: LoginCallback }

]
// 创建路由实例
const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHistory(process.env.BASE_URL),
  routes,
  // 每次切换路由的时候滚动到顶部
  scrollBehavior () {
    // 添加滚动
    return { left: 0, top: 0, behavior: 'smooth' }
  }
})

export default router
